/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sesame.domain.Album;
import com.sesame.domain.Answer;
import com.sesame.domain.Ask;
import com.sesame.domain.Guestbook;
import com.sesame.domain.User;
import com.sesame.service.AlbumService;
import com.sesame.service.ContactService;
import com.sesame.service.UserService;

/**
 * @author voidman
 * 
 */
public class AskDetailController extends AbstractController {

    private UserService userService;

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @SuppressWarnings("unchecked")
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Map model = new HashMap();
        Integer askId = Integer.parseInt(request.getParameter("askId"));
        String content = request.getParameter("content");

        if (content != null && !content.equals("")) {
            userService.newAnswer(askId, content, request);
        }

        List<Answer> answerList = userService.listAnswer(askId);
        Ask ask = userService.showAsk(askId);

        model.put("ask", ask);
        model.put("answerList", answerList);

        return new ModelAndView("askDetail", model);

    }

}